package PUSHSendIntegrator;

import DatabaseManager.*;
import java.sql.SQLException;
import java.util.Random;

public class NotificationInd extends PUSHMmsMessage{
	public String notificationIndMessage;
	
	public NotificationInd() {
		notificationIndMessage = "";
		notificationIndMessage += MMS_MESSAGE_TYPE +" "+ MMS_MESSAGE_TYPE_NOTI_IND + NL;
	}
	public NotificationInd(String msgId, String from, boolean store) {
		notificationIndMessage = "";
		notificationIndMessage += MMS_MESSAGE_TYPE + MMS_MESSAGE_TYPE_NOTI_IND + NL;
		this.mmsMessageID = msgId;
		this.mmsFrom = from;
		this.mmsStore = store;
	}

	public String toString() {
		
		//Mandatory!! 
		if(!isTransactionIDSet()) return "transactionID not defined";
		if(!isVersionSet()) return "Version not defined";
		if(!isMessageSizeSet()) return "Version not defined";
		if(!isMessageExpiryTimeSet()) return "Version not defined";		
		if(!isContentLocationValue()) return "Version not defined";
		
		notificationIndMessage += MMS_TRANSACTION_ID + " " + this.getTransactionID() + NL;
		notificationIndMessage += MMS_VERSION + " " + this.getVersion() + NL;
		notificationIndMessage += MMS_MESSAGE_SIZE + " " + this.getMessageSize() + NL;
		notificationIndMessage += MMS_EXPIRY + " " + this.getMessageExpiryTime() + NL;
		notificationIndMessage += MMS_CONTENT_LOCATION_VALUE + " " + this.getContentLocationValue() + NL;

		//Optional!! 		
		if(isMessageSenderSet())
			notificationIndMessage += MMS_FROM + " " + this.getMessageSender() + NL;
		if(isMessageSubjectSet())
			notificationIndMessage += MMS_SUBJECT + " " + this.getMessageSubject() + NL;
		if(isDeliveryReportSet())
			if(isDeliveryReportSet()) notificationIndMessage += MMS_DELIVERY_REPORT + " " + MMS_DELIVERY_REPORT_YES + NL;
			else notificationIndMessage += MMS_DELIVERY_REPORT + " " + MMS_DELIVERY_REPORT_NO + NL;
		
		if(isStoreEnabled())
			if(isStoreEnabled()) notificationIndMessage += MMS_STORE + " " + MMS_STORE_YES + NL;
			else notificationIndMessage += MMS_STORE + " " + MMS_STORE_NO + NL;

		return notificationIndMessage;
	}
	
	public String MakeTransactionId() throws SQLException{
		PDUMSGBox pduMsgBox = new PDUMSGBox();
		mmsTransactionId = null;
		
		pduMsgBox.ConnectDB();
		do{
			Random random = new Random(System.currentTimeMillis());
			int randomValue = random.nextInt(); 
			mmsTransactionId = "TID" + randomValue;
		}while(pduMsgBox.IsExistTid(mmsTransactionId));
		pduMsgBox.CloseConnectionDB();		
		System.out.println("me????");
		return mmsTransactionId;
	}
}